//
//  OrderCommentViewController.m
//  YaDiuDiu
//
//  Created by 樊亮 on 2017/10/28.
//  Copyright © 2017年 jy. All rights reserved.
//

#import "OrderCommentViewController.h"
#import "RatingBar.h"
#import "PlaceholderTextView.h"

@interface OrderCommentViewController ()<UITextViewDelegate,UIActionSheetDelegate,UINavigationControllerDelegate>
{
    RatingBar *_ratingBar1;
    RatingBar *_ratingBar2;
    NSString *_photoNum;
    NSString * _commentStr1;
    NSString * _commentStr2;
}

@property (weak, nonatomic) IBOutlet UIView *view2;
@property (weak, nonatomic) IBOutlet UIView *view1;
@property (nonatomic,retain)PlaceholderTextView *holderTextView1;
@property (nonatomic,retain)PlaceholderTextView *holderTextView2;
@property (weak, nonatomic) IBOutlet UIButton *submitBtn;

@end

@implementation OrderCommentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self showNav:@"评论"];
    
    _ratingBar1 = [[RatingBar alloc]initWithFrame:CGRectMake(0,44, 150, 29)];
    _ratingBar1.starNumber = 5;
    [self.view1 addSubview:_ratingBar1];
    
    _holderTextView1 = [[PlaceholderTextView alloc] init];
    _holderTextView1.frame = CGRectMake(12, 78, ScreenWidth - 24, 95);
    _holderTextView1.font = [UIFont systemFontOfSize:14.f];
    _holderTextView1.placeholder = @"请填写评论";
    _holderTextView1.tag = 100;
    _holderTextView1.delegate = self;
    _holderTextView1.layer.borderWidth = 0.5;
    _holderTextView1.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    [self.view1 addSubview:_holderTextView1];
    
    _ratingBar2 = [[RatingBar alloc]initWithFrame:CGRectMake(0,44, 150, 29)];
    _ratingBar2.starNumber = 5;
    [self.view2 addSubview:_ratingBar2];
    
    _holderTextView2 = [[PlaceholderTextView alloc] init];
    _holderTextView2.frame = CGRectMake(12, 78, ScreenWidth - 24, 95);
    _holderTextView2.font = [UIFont systemFontOfSize:14.f];
    _holderTextView2.layer.borderWidth = 0.5;
    _holderTextView2.layer.borderColor = [UIColor groupTableViewBackgroundColor].CGColor;
    _holderTextView2.placeholder = @"请填写评论";
    _holderTextView2.tag = 200;
    _holderTextView2.delegate = self;
    [self.view2 addSubview:_holderTextView2];
}

#pragma mark **********textViewDelegate**********

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}

- (void)textViewDidChange:(UITextView *)textView {
    NSInteger number = textView.text.length;
    if (number > 100) {
        //        NSLog(@"文字评价内容超出200字");
    }else{
        // 获取输入的内容
        if (textView.tag == 100) {
            _commentStr1 = textView.text;
        }if (textView.tag == 200) {
            _commentStr2 = textView.text;
        }
    }
}

#pragma mark --- 提交

/*
 验证Token
 用户ID
 订单ID
 商家ID
 评星等级
 评论内容
 订单类型ID
 骑手评星
 评论骑手内容
 干洗多个骑手对第二个骑手评论星级
 干洗多个骑手对第二个骑手评论内容
 */

- (IBAction)submitBtn:(id)sender {
    
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    NSString *str = [NSString stringWithFormat:@"%@890d69e502d1d37a9e84335ccefece57",[user objectForKey:@"token2"]];
    NSString *token = [LCMD5Tool md5:str];
    NSMutableDictionary *parmas = [NSMutableDictionary dictionary];
    
    params[@"verifyToken"] = token;
    params[@"userid"] = [user objectForKey:@"userid"];
    params[@"orderid"] = self.model.id;
    params[@"merchantid"] = self.model.merchantid;
    params[@"star"] = @"5";
    params[@"comment"] = @"";
    params[@"orderTypeId"] = self.model.typeid;
    params[@"rider_star"] = @"5";
    params[@"rider_comment"] = @"";
    params[@"commentlevel"] = @"";
    params[@"commentcontent"] = @"";

    [[AFHTTPSessionManager manager] POST:@"" parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        
        if ([responseObject[@"status"] integerValue] == 200) {
            
            [LICGToast showWithText:responseObject[@"msg"]];
            [self.navigationController popViewControllerAnimated:YES];
        }
        
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
        [SVProgressHUD showErrorWithStatus:@"网络异常"];
    }];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
